package controller

import (
	"api/app/wms/auto/v1/api"
	"api/app/wms/models"
	"api/app/wms/services"
	"gitee.com/dreamwood/ez/server"
)

type ItemBaseController struct {
	api.ItemBaseApi
}

func init() {

	c := &ItemBaseController{}
	c.Prepare()
	c.AddRoute("/list", c.ListAction)
	c.AddRoute("/get", c.GetAction)
	c.AddRoute("/scan", c.ScanAction)
	c.AddRoute("/choice", c.ChoiceAction)
	c.AddRoute("/save", c.SaveAction)
	c.AddRoute(`/save_many`, c.SaveManyAction)
	c.AddRoute("/delete", c.DeleteAction)
	c.AddRoute("/delete_many", c.DeleteManyAction)
	c.AddRoute("/copy", c.CopyAction)
	c.AddRoute("/gen_sku", c.GenSkuAction)
}

// 如果不满意自动生成的方法，请自定义，本文件不会被生成器覆盖，请放心操作
// func (this *ItemBaseController) SaveAction(operation *server.Operation) {}
// func (this *ItemBaseController) GetAction(operation *server.Operation) {}
// func (this *ItemBaseController) ScanAction(operation *server.Operation) {}
// func (this *ItemBaseController) ListAction(operation *server.Operation) {}
// func (this *ItemBaseController) DeleteAction(operation *server.Operation) {}

func (c *ItemBaseController) GenSkuAction(operation *server.Operation) {
	this := c.TakeOver(operation)
	id := this.Get("id").IsInt()
	crud := models.NewItemBaseCrud()
	itemBase, e := crud.Find(id)
	if this.CheckError(e) {
		return
	}
	services.UpdateItemSku(itemBase)
	this.ReturnSuccess("OK", "开始生成")
}
